package com.hd.crdao.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.hd.crdao.R;
import com.hd.crdao.base.MyBaseAdapter;
import com.hd.crdao.bean.CarInfoListBean;
import com.hd.crdao.config.Constants;
import com.hd.crdao.utils.UIUtils;
import com.hd.crdao.wrapper.GlideImageUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;

/**
 *
 *@author senjoeson
 *@date 2017/5/17 0017
 */
public class OldCarInfoAdapter extends MyBaseAdapter<CarInfoListBean> {



    public OldCarInfoAdapter(List<CarInfoListBean> dataSets) {
        super(dataSets);
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = View.inflate(UIUtils.getContext(), R.layout.car_detail_item, null);
            viewHolder.mIvPic = (ImageView) convertView.findViewById(R.id.ivPic);
            viewHolder.mTvDesc = (TextView) convertView.findViewById(R.id.tvDesc);
            viewHolder.mTvDate = (TextView) convertView.findViewById(R.id.tvDate);
            viewHolder.mTvUseLength = (TextView) convertView.findViewById(R.id.tvUseLength);
            viewHolder.mTvLocation = (TextView) convertView.findViewById(R.id.tvLocation);
            viewHolder.mSumPrice = (TextView) convertView.findViewById(R.id.sumPrice);
            viewHolder.mFirstPayDesc = (TextView) convertView.findViewById(R.id.firstPayDesc);
          //  viewHolder.mSpecificLocation = (TextView) convertView.findViewById(R.id.specificLocation);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        CarInfoListBean carInfoListBean = mDataSets.get(position);
        viewHolder.mTvDesc.setText(carInfoListBean.getVehConfig().getVcTypenme());
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM", Locale.CHINESE);
        try {
           Date date = sdf.parse(carInfoListBean.getCreateDate());
            String format = sdf.format(date);
            viewHolder.mTvDate.setText(format);
        } catch (ParseException e) {
            e.printStackTrace();
        }
     //   viewHolder.mSpecificLocation.setText(carInfoListBean.getCiPlatearea());
        viewHolder.mTvUseLength.setText(String.valueOf(carInfoListBean.getCiMileage())+"万公里");
        viewHolder.mSumPrice.setText(String.valueOf(carInfoListBean.getCiExpectprice())+"万");
        String imageurl = carInfoListBean.getCoverPath();
        viewHolder.mTvLocation.setText(carInfoListBean.getCiPlatearea());
        GlideImageUtils.loadImage(Constants.IMAGEURL + imageurl,R.drawable.logo_moren_2x,viewHolder.mIvPic);


        return convertView;
    }


    class ViewHolder {

        ImageView mIvPic;
        TextView mTvDesc;
        TextView mTvDate;
        TextView mTvUseLength;
        TextView mTvLocation;
        TextView mSumPrice;
        TextView mFirstPayDesc;
      //  TextView mSpecificLocation;


    }
}


